package com.huishu.order.fegin.fallback;

import com.huishu.commons.pojo.Result;
import com.huishu.commons.pojo.dto.FindAvailableCouponDTO;
import com.huishu.commons.pojo.dto.ReturnUserCouponDTO;
import com.huishu.commons.pojo.dto.SendRepurchaseDTO;
import com.huishu.commons.pojo.dto.UseCouponDTO;
import com.huishu.commons.pojo.vo.CouponVO;
import com.huishu.order.fegin.CouponFeignClient;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @ClassName：CouponFeignClientFallBack
 * @Author: ljj
 * @Date: 2023/4/11 15:01
 */
@Slf4j
@Component
public class CouponFeignClientFallBack implements FallbackFactory<CouponFeignClient> {
    @Override
    public CouponFeignClient create(Throwable throwable) {
        String msg = throwable == null ? "" : throwable.getMessage();
        if (!StringUtils.isEmpty(msg)) {
            log.error(msg);
        }
        return new CouponFeignClient() {

            @Override
            public Result<List<CouponVO>> findAvailableCoupon(FindAvailableCouponDTO findAvailableCouponDTO) {
                return Result.fail(msg);
            }

            @Override
            public Result<List<CouponVO>> findCouponByUserId(Long userId, List<Long> categoryId) {
                return Result.fail(msg);
            }

            @Override
            public Result<List<CouponVO>> findRepurchaseByUserId(Long userId, List<Long> categoryId) {
                return Result.fail(msg);
            }

            @Override
            public Result useCoupon(List<UseCouponDTO> useCouponDTOs) {
                return Result.fail(msg);
            }

            @Override
            public Result returnUserCoupon(ReturnUserCouponDTO returnUserCouponDTO) {
                return Result.fail(msg);
            }

            @Override
            public Result sendRepurchase(SendRepurchaseDTO sendRepurchaseDTO) {
                return Result.fail(msg);
            }

            @Override
            public Result deleteRepurchase(Long userId) {
                return Result.fail(msg);
            }

            @Override
            public Result<Map<Long, Boolean>> findRepurchaseByProductIds(List<Long> ids) {
                return Result.fail(msg);
            }

            @Override
            public Result<List<CouponVO>> findByCouponIds(List<Long> couponIds) {
                return Result.fail(msg);
            }
        };
    }
}
